
import { _decorator, Component, Label } from "cc";
import I18nManager, { LanguageType } from "./I18nManager";


const { ccclass, property } = _decorator;

@ccclass
export default class I18nLabel extends Component {

    @property({ displayName: '英语 / en', visible() { return I18nManager.instance.isSupportLanguage(LanguageType.en); } })
    enString: string = '';
    @property({ displayName: '英语 / en', visible() { return I18nManager.instance.isSupportLanguage(LanguageType.ko); } })
    koString: string = '';
    @property({ displayName: '英语 / en', visible() { return I18nManager.instance.isSupportLanguage(LanguageType.ja); } })
    jaString: string = '';

    onLoad() {
        this.switchLanguage(I18nManager.instance.language);
        I18nManager.instance.registerLabel(this)
    }

    switchLanguage(type: LanguageType) {
        switch (type) {
            case LanguageType.en: {
                this.getComponent(Label).string = this.enString;
                break;
            }
            case LanguageType.ko: {
                this.getComponent(Label).string = this.koString;
                break;
            }
            case LanguageType.ja: {
                this.getComponent(Label).string = this.jaString;
                break;
            }
        }
    }
}
